<template>
    <border-box title="信息反馈">
        <div class="feedback-title">历史反馈：</div>
        <a-empty v-if="!feedbackHistory || feedbackHistory.length === 0"></a-empty>
        <a-timeline v-else class="feedback-content">
            <a-timeline-item v-for="item in feedbackHistory" :key="item.id">
                <div>
                    {{item.createTime}}
                    <div>{{item.createBy}}</div>
                </div>
                <div v-if="item.feedback" class="content">{{item.feedback}}</div>
                <j-upload class="history-upload" v-if="item.attachment" :disabled="true" :return-url="true" v-model="item.attachment"></j-upload>
            </a-timeline-item>
        </a-timeline>
        <template v-if="!disabled">
            <div class="feedback-title">添加反馈信息：</div>
            <a-textarea v-model.trim="feedback" placeholder="请输入反馈信息"></a-textarea>
            <j-upload style="margin-top: 10px;" :return-url="true" v-model="attachment"></j-upload>
        </template>
    </border-box>
</template>

<script>
  import BorderBox from './BorderBox'
  import { postAction,getAction } from '../../api/manage'

  export default {
    name: 'Feedback',
    components: { BorderBox },
    props: ['params','disabled'],
    data() {
      return {
        feedback: '',
        attachment: '',
        feedbackHistory: []
      }
    },
    created() {
      this.queryFeedback();
    },
    methods: {
      // fileChange(fileList) {
      //   const files = fileList.map(item => {
      //     return {
      //       name: item.fileName,
      //       url: item.filePath
      //     };
      //   });
      // }
      async queryFeedback() {
        const res = await getAction('task/taskInfo/getFeedbackByTaskAndNode', this.params);
        if (res.success) {
          this.feedbackHistory = res.result;
        }
      },
      selfValidate() {
        return new Promise(async (resolve, reject) => {
          const success = await this.saveFeedback();
          if (success) {
            resolve({})
          } else {
            reject('信息反馈保存失败')
          }
        })
      },
      async saveFeedback() {
        if (this.feedback || this.attachment) {
          const params = { ...this.params }
          if (this.feedback) {
            params.feedback = this.feedback
          }
          if (this.attachment) {
            params.attachment = this.attachment
          }
          const res = await postAction('task/taskInfo/saveTaskFeedBack', params)
          if (res.success) {
            return true
          } else {
            this.$message.error(res.message);
            return false
          }
        }
        return true;
      }
    }
  }
</script>
<style>
    .history-upload .ant-upload-select{
        display: none;
    }
</style>
<style scoped lang="less">
    .feedback-title {
        color: #333333;
        font-size: 13px;
        margin-bottom: 10px;
    }
    .feedback-content{
        color: #666666;
        font-size: 13px;
        .content{
            margin-top: 5px;
            font-size: 13px;
            color: #999999;
        }
    }

</style>
